package cate.game.attr;

import cate.common.table.item.kitchenware.row.KitchenwareMasterRow;
import cate.game.play.support.PlayBuildContext;
import cate.game.role.bag.kitchenware.Kitchenware;
import cate.game.role.bag.kitchenware.KitchenwaresOn;

import java.util.Comparator;

public class KitchenwaresPowerAttrPart extends PowerAttrPart{
    public KitchenwaresPowerAttrPart(){}

    public KitchenwaresPowerAttrPart(PlayBuildContext ctx, KitchenwaresOn po) {
        if (po == null) {
            return;
        }
        FightAttr attr = new FightAttr();
        this.powerExt = 0;
        if (po.kitchenwareMap != null) {
            for (Kitchenware kitchenware : po.kitchenwareMap.values()) {
                attr.add(kitchenware.getPowerAttr(ctx));
            }
            if (po.kitchenwareMap.size() == 4) {
                int minLevel = po.kitchenwareMap.values().stream().min(Comparator.comparingInt(e -> e.maxLevel)).get().maxLevel;
                FightAttr masterAttr = new FightAttr();
                KitchenwareMasterRow row = null;
                for (KitchenwareMasterRow masterRow : ctx.kitchenwareExcel().master.getList()) {
                    if (minLevel >= masterRow.levelLimit) {
                        row = masterRow;
                    }
                }
                if (row != null) {
                    masterAttr.add(new FightAttr(row.attrStr));
                }
                attr.add(masterAttr);
            }
        }
        this.attr = attr;
        this.skills = po.getSkills(ctx);
    }
}
